<?php
/**
 * PhpStorm
 * User: zucheng
 * Date: 2019/5/6
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\MsgFee;
use Illuminate\Http\Request;

class MsgFeeController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $status = MsgFee::$payStatusDesc;
        return view('admin.msg-fee.index', compact('status'));
    }

    public function data(Request $request)
    {
        $model = MsgFee::query();
        if ($request->get('start_time')) {
            $model = $model->where('created_at', '>=', $request->get('start_time'));
        }
        if ($request->get('end_time')) {
            $model = $model->where('created_at', '<=', $request->get('end_time'));
        }
        if ($request->get('out_trade_no')) {
            $model = $model->where('out_trade_no', $request->get('out_trade_no'));
        }
        if ($request->get('status')) {
            $model = $model->where('pay_status', $request->get('status'));
        }
        $res = $model->with(['order', 'driver'])
            ->orderBy('created_at', 'desc')
            ->paginate($request->get('limit', 30))
            ->toArray();

        if ($res['total'] > 0) {
            foreach ($res['data'] as $key => &$item) {
                $item['pay_desc'] = MsgFee::$payStatusDesc[$item['pay_status']];
            }
        }

        return $this->table($res['data'], $res['total']);
    }

}